package com.atguigu.blog.controller;

import com.atguigu.blog.pojos.Category;
import com.atguigu.blog.result.PageResult;
import com.atguigu.blog.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author CF
 * @date 2023/8/19 8:54
 */

@RestController
@RequestMapping(value = "/category")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;

    @PostMapping("queryList")
    public List<Category> queryList(){
        return categoryService.queryList();
    }

    @PostMapping("/queryListPage/{pageNum}/{pageSize}")
    public PageResult<Category>  queryListPage(@PathVariable("pageNum") Integer pageNum,
                                               @PathVariable("pageSize") Integer pageSize,
                                               @RequestBody Category category){
        return categoryService.queryListPage(pageNum,pageSize,category);
    }
    @PutMapping("/updateCategory")
    public boolean updateCategory(@RequestBody Category category){
        return categoryService.updateCategory(category);
    }

    @PostMapping ("/addCategory")
    public boolean addCategory(@RequestBody Category category){
        return categoryService.addCategory(category);
    }
    @DeleteMapping("/deleteCategory/{cid}")
    public boolean deleteCategory(@PathVariable("cid") Integer cid){
        return categoryService.deleteCategoryById(cid);
    }


}
